package com.canbot.u05.activity.presidemode.newcode.view;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

import com.canbot.u05.R;
import com.canbot.u05.view.MyRecordView;


/**
 * @author zmp 语音录入对话框
 */

public class NGuideRecordDialog extends Dialog implements View.OnClickListener {

    private MyRecordView myRecordView;

    public NGuideRecordDialog(Context context, IRecodeListener recodeListener) {
        super(context, R.style.MyDialogStyle);
        this.recodeListener = recodeListener;
        setCancelable(false);
        setCustomDialog();

    }

    private void setCustomDialog() {
        View mView = LayoutInflater.from(getContext()).inflate(R.layout.ndialog_recode_voice, null);
        super.setContentView(mView);
        myRecordView = findViewById(R.id.mrv);
        myRecordView.setErrorListener(() -> {
            dismiss();
            recodeListener.error();
        });
        findViewById(R.id.finish_bt).setOnClickListener(this);
        findViewById(R.id.cancel_bt).setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.finish_bt:
                int time = myRecordView.getTime();
                String fileName = myRecordView.ok();
                dismiss();
                recodeListener.finish(fileName,time);
                break;
            case R.id.cancel_bt:
                myRecordView.cancel();
                dismiss();
                recodeListener.cancel();
                break;
        }
    }

    @Override
    public void show() {
        super.show();
        myRecordView.startRecord();
    }

    private IRecodeListener recodeListener;

    public interface IRecodeListener {

        void finish(String fileName,int time );

        void cancel();

        void error();
    }
}
